home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-04-26 | 2.1 KB | 79 lines |
- /* Exercise - Ticker.class */
- import java.applet.*;
- import java.awt.* ;
-
- public class Ticker extends Applet implements Runnable {
- Thread tkthread = null;
- String tktext = "Exercise - ticker tape";
- int tkspd = 1;
- String tkfname = "TimesRoman";
- int tkfsz = 12;
- Font tkfont = null;
- String tkdirection = "Left";
- Dimension tksize = null;
- int tktextwth = 0;
- int tktexthgt = 0;
- int tkpos = -63000;
-
- public void init() {
- String getval = null;
- getval = getParameter("tktext");
- tktext = (getval == null ) ? tktext : getval;
- getval = getParameter("tkspd");
- tkspd = (getval == null ) ? tkspd : (Integer.valueOf(getval).intValue());
- getval = getParameter("tkfname");
- tkfname = (getval == null) ? tkfname : getval ;
- getval = getParameter("tkfsz");
- tkfsz = (getval == null ) ? tkfsz : (Integer.valueOf(getval).intValue());
- tkfont = new java.awt.Font( tkfname, Font.PLAIN, tkfsz ) ;
- getval = getParameter("tkreverse");
-
- tkdirection = "Left";
- tkpos = -63000 ;
-
- if ( getval != null ) {
- if ( getval.equalsIgnoreCase( "Yes") ) {
- tkdirection = "Right";
- tkpos = 63000;
- }
- }
-
- this.setBackground( Color.white );
- }
-
- public void start() {
- tkthread = new Thread(this);
- tkthread.start();
- }
-
- public void stop() {
- tkthread.stop();
- }
-
- public void run() {
- Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
- while (true) {
- try {Thread.sleep( 10 ); } catch (InterruptedException e){}
- repaint();
- }
- }
-
- public void paint(Graphics tk) {
- tksize = size();
- tk.setFont(tkfont);
- FontMetrics tkfm = tk.getFontMetrics();
- tktexthgt = ( tktexthgt==0 ) ? tkfm.getHeight() : tktexthgt;
- tktextwth = ( tktextwth==0 ) ? tkfm.stringWidth( tktext ) : tktextwth;
- if (tkdirection=="Left") {
- tkpos = ( tkpos <= tktextwth * -1 ) ? tksize.width : tkpos - tkspd;
- }
- else{
- tkpos = ( tkpos > tksize.width ) ? 0 - tktextwth: tkpos + tkspd;
- }
- tk.setColor(Color.black);
- tk.drawString( tktext, tkpos, ( tksize.height + tktexthgt ) / 2 );
- }
- }
-
-
-